class AlterOuterExpensesColumn < ActiveRecord::Migration
  def self.up
    # 添加地接费
    add_column :outer_expenses, :acceptance_cost, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false
    # 车费，餐费，门票，导贴4项取消，以：“地接费” 代替
    execute "update outer_expenses set acceptance_cost = travel_cost + food_cost + ticket_cost + subsidy_for_guide"
    # 删除车费，餐费，门票，导贴
    remove_column :outer_expenses, :travel_cost
    remove_column :outer_expenses, :food_cost
    remove_column :outer_expenses, :ticket_cost
    remove_column :outer_expenses, :subsidy_for_guide
    # 增加船票
    add_column :outer_expenses, :boatticket_cost, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false
  end

  def self.down
    remove_column :outer_expenses, :boatticket_cost
    
    add_column :outer_expenses, :travel_cost, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false
    add_column :outer_expenses, :food_cost, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false
    add_column :outer_expenses, :ticket_cost, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false
    add_column :outer_expenses, :subsidy_for_guide, :decimal, :precision => 8, :scale => 2, :default => 0, :null => false

    execute "update outer_expenses set travel_cost = acceptance_cost"
    remove_column :outer_expenses, :acceptance_cost
  end
end
